package com.hst.capacity.infra.persistence.jpa.setting.price;

import com.hst.capacity.domain.model.entity.setting.price.IntercityPriceEntity;
import com.hst.capacity.domain.model.response.setting.price.IntercityPriceVO;
import com.hst.capacity.domain.model.response.setting.price.IntercitySearchVO;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

public interface IcPriceRepository extends CrudRepository<IntercityPriceEntity, Integer> {

    /**
     * 通过城市线路查找线路价格
     * @param idLine
     * @return
     */
    IntercityPriceEntity findByIdLine(String idLine);

    @Query("select new com.hst.capacity.domain.model.response.setting.price.IntercitySearchVO(p,l) from IntercityPriceEntity p left join IntercityLineEntity l on p.idLine = l.idLine where p.idFranchisee=:idFranchisee")
    Page<IntercitySearchVO> findByIdFranchisee(String idFranchisee, PageRequest pageRequest);

    IntercityPriceEntity findByIdFranchiseeAndIdLine(String idFranchisee, String idLine);

    @Query("select new com.hst.capacity.domain.model.response.setting.price.IntercityPriceVO(p,l,cl) from IntercityPriceEntity p left join IntercityLineEntity l on p.idLine=l.idLine left join CityLineEntity cl on l.idCityLine = cl.idCityLine where p.idIntercityLinePrice=:idPrice and cl.idCityLine is not null")
    IntercityPriceVO findByIdPrice(Integer idPrice);

    @Query("select new com.hst.capacity.domain.model.response.setting.price.IntercityPriceVO(p,l,cl) from IntercityPriceEntity p left join IntercityLineEntity l on p.idLine=l.idLine left join CityLineEntity cl on l.idCityLine = cl.idCityLine where p.idLine=:idLine and cl.idCityLine is not null")
    IntercityPriceVO findBbyIdLine(String idLine);

}
